package cn.xy.ymcc.mq;

import cn.xy.ymcc.domain.MessageStation;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessageStationProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    /**
     * 发送消息是否成功
     */
    public boolean sendMessage(MessageStation messageStation){
        String messageStationJsonStr  = JSON.toJSONString(messageStation);
        //发送
        SendResult sendResult = rocketMQTemplate.syncSend("messageStation-topic:messageStation-tags", messageStationJsonStr);
        //获取发送状态是否发送成功
        SendStatus sendStatus = sendResult.getSendStatus();
        return sendStatus == SendStatus.SEND_OK;
    }
}